package conf

import (
	"github.com/go-ini/ini"
	"log"
)

type Config struct {
	Server   Server   `ini:"server"`
	Redis    Redis    `ini:"redisTool"`
	Mysql    Mysql    `ini:"mysql"`
	Jwt      Jwt      `ini:"jwtTool"`
	Security Security `ini:"security"`
}
type Server struct {
	Port int `ini:"port"`
}

type Redis struct {
	Host     string `ini:"host"`
	Port     int    `ini:"port"`
	Db       int    `ini:"db"`
	Password string `ini:"password"`
}

type Mysql struct {
	Host     string `ini:"host"`
	Port     string `ini:"port"`
	DbName   string `ini:"dbName"`
	Username string `ini:"username"`
	Password string `ini:"password"`
}

type Jwt struct {
	SecurityKey string `ini:"securityKey"`
	expireTime  int    `ini:"expireTime"`
}

type Security struct {
	captcha bool `ini:"captcha"`
	SSO     int  `ini:"SSO"`
}

// GlobalConfig 全局配置
var GlobalConfig Config

func InitConfig() {
	load, err := ini.Load("./conf/config.ini")
	if err != nil {
		log.Panicln("读取配置文件失败：", err.Error())
	}

	err = load.MapTo(&GlobalConfig)
	log.Println(GlobalConfig)
	if err != nil {
		log.Panicln("配置文件错误！请检查配置文件", err.Error())
	}
}
